#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct nameless {
	char word[201];
	int count;
};

static int
cmpstringp(const void *p1, const void *p2)
{
	/* The actual arguments to this function are "pointers to
	 * pointers to char", but strcmp(3) arguments are "pointers
	 * to char", hence the following cast plus dereference
	 */

	return strcmp(* (char * const *) p1, * (char * const *) p2);
}

static int
cmpnamelessp(const void *p1, const void *p2)
{
	struct nameless *n1 = p1;
	struct nameless *n2 = p2;

	if (n1->count != n2->count)
		return n2->count - n1->count;
	else
		return strcmp(n1->word, n2->word);
}

int
main(int argc, char **argv)
{
	static char *words[10001];
	static char buf[202], *p = NULL;
	int w_len = 0;
	int i = 0, j = 0, k = 0, n = 0;
	static struct nameless D[10000];

	p = buf;
	while (scanf("%s", p) == 1) {
		w_len = strlen(buf);
		if (buf[w_len - 1] == '-') {
			p = &buf[w_len - 1];
			continue;
		}

		words[n++] = strdup(buf);
		p = buf;
	}

	qsort(words, (size_t) n, sizeof words[0],
			cmpstringp);

	i = j = 0;
	while (i < n) {
		while (j < n && strcmp(words[i], words[j]) == 0)
			j++;

		/* printf("%s %d\n", words[i], j - i); */
		strcpy(D[k].word, words[i]);
		D[k++].count = j - i;

		i = j;
	}
	qsort(D, (size_t) k, sizeof D[0], cmpnamelessp);

	for (i = 0; i < k; i++)
		printf("%s %d\n", D[i].word, D[i].count);

	for (i = 0; i < n; i++)
		free(words[i]);

	return 0;
}
